<template>
  <PageWrapper>
    <template #headerContent> <WorkbenchHeader /> </template>
      <BasicTable @register="registerTable" >
        <template #action="{ record }">
          <TableAction :actions="getTableAction(record)" />
        </template>
    </BasicTable>

    <AuditModal @register="registerModal" @success="handleSuccess"></AuditModal>
  </PageWrapper>

  
</template>
<script lang="ts" setup>
  import { ref,onMounted } from 'vue';
  import { Card } from 'ant-design-vue';
  import { PageWrapper } from '/@/components/Page';
  import WorkbenchHeader from './components/WorkbenchHeader.vue';
  import ProjectCard from './components/ProjectCard.vue';
  import QuickNav from './components/QuickNav.vue';
  import DynamicInfo from './components/DynamicInfo.vue';
  import SaleRadar from './components/SaleRadar.vue';
  import AuditModal from './components/AuditModal.vue';
  import { ActionItem, BasicColumn, BasicTable, TableAction } from '/@/components/Table';
  import {attApplyResultTodoTask,} from './Analysis.api'
  import { useListPage } from '/@/hooks/system/useListPage';
  import {useModal} from '/@/components/Modal';
  const [registerModal, {openModal}] = useModal();


  const dataSource = ref([])
  const loading = ref(true);
  const auditObj = ref({})
  const listColumns =  ref([
    // {
    //   title: '姓名',
    //   dataIndex: 'name',
    // },
    {
      title: '时间',
      dataIndex: 'howLongAgo',
    },
    {
      title: '标题',
      dataIndex: 'title',
    },
    
  ])
  const { tableContext } = useListPage({
    designScope: 'basic-table-demo',
    tableProps: {
      // title: '用户列表',
      dataSource,
      columns: listColumns,
      size: 'large', //紧凑型表格 large
      striped: false, //斑马纹设置 false
      showActionColumn: true,
      useSearchForm: false,
    },
  });
  const [registerTable, methods] = tableContext;

  

  function getTableAction(record): ActionItem[] {
    return [
      {
        label: '审核',
        onClick: handleAudit.bind(null, record),
      },
    ];
  }


  function handleAudit(record){
    // console.log(record);
    // auditObj.value = record
    // console.log(auditObj.value);
    openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
  }

  function handleSuccess(){
    setTimeout(()=>{
      getData()
    },1000)
  }

  setTimeout(() => {
    loading.value = false;
  }, 500);
  function getData(){
    attApplyResultTodoTask().then(res=>{
      dataSource.value = []
      dataSource.value = res
    })

  }
  onMounted(()=>{
    getData()
  })
</script>
